package com.yun.datastructure.tree.binarysearchtree.leetcode;

import com.yun.datastructure.tree.binarytree.domain.TreeNode;

public class Leetcode938 {
    public int rangeSumBST(TreeNode node, int low, int high) {
        if(node==null){
            return 0;
        }
        if(node.val<low){
            return rangeSumBST(node.right,low,high);
        }
        if(node.val>high){
            return rangeSumBST(node.left,low,high);
        }
        return node.val+rangeSumBST(node.right,low,high)+rangeSumBST(node.left,low,high);
    }
}
